/* 
泛型类
*/
 /* 
  1. 声明泛型类型: 在类名的右侧  <T>   // T K V
  2. 使用泛型: 类体中
  3. 指定泛型的具体类型: 创建类的实例时, 类名的右侧 <具体类型>
  */

(() => {
  class GenericData <T> {
    zeroValue: T;
    add: (x: T, y: T) => T
  }
  
  const genericNumber = new GenericData<number>()
  genericNumber.zeroValue = 4
  genericNumber.add = function (x, y) {
    return x + y
  }
  console.log(genericNumber.add(genericNumber.zeroValue, 5))
  
  
  let genericString = new GenericData<string>()
  genericString.zeroValue = 'abc'
  genericString.add = function(x, y) { 
    return x + y
  }
  console.log(genericString.add(genericString.zeroValue, '23'))
})()